package com.itheima.a01mymap;

import java.util.HashMap;
import java.util.Map;

public class A02_HashMapDemo2 {
    public static void main(String[] args) {
        //创建hashmap集合
        HashMap<Student2,String> hm = new HashMap<>();

        //添加80个学生
        Student2 s1 = new Student2("John", "A");
        Student2 s2 = new Student2("zhangsan", "A");
        Student2 s3 = new Student2("lisi", "B");
        Student2 s4 = new Student2("wangwu", "C");

        hm.put(s1,s1.getChoose());
        hm.put(s2,s2.getChoose());
        hm.put(s3,s3.getChoose());
        hm.put(s4,s4.getChoose());

        int A=0;
        int B=0;
        int C=0;
        int D=0;

        //遍历得到选项（value)求和
        for (Map.Entry<Student2, String> entry : hm.entrySet()) {
            String value = entry.getValue();
            //判断
            if(value=="A"){
                A++;
            }else if(value=="B"){
                B++;
            }else if(value=="C"){
                C++;
            }else if(value=="D"){
                D++;
            }
        }

        System.out.println("A:"+A);
        System.out.println("B:"+B);
        System.out.println("C:"+C);
        System.out.println("D:"+D);
    }
}
